import javax.swing.ImageIcon;
import javax.swing.JFrame;

import java.awt.BorderLayout;

import java.awt.Color;
import javax.swing.JLabel;

import java.awt.Dimension;

import java.awt.Component;
import java.awt.Font;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.SwingConstants;



public class GameScreen extends JFrame {
	public JLabel label = new JLabel("");
	public boolean lost = false;
	private JLabel scoreLab = new JLabel("");
	private JLabel highScore = new JLabel("");
	
	public GameScreen() 
	{
		
		setSize(new Dimension(550, 650));
		setMinimumSize(new Dimension(550, 650));
		setMaximumSize(new Dimension(550, 650));
		setTitle("2048");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		getContentPane().setLayout(null);
		
		
		//Location of grid
		label.setBounds(90, 50, 525, 600);
		getContentPane().add(label, BorderLayout.CENTER);
		label.setIcon(new ImageIcon("2048Game.jpg"));
		getContentPane().add(label);
		
		JLabel name = new JLabel("2048");
		name.setAlignmentX(Component.CENTER_ALIGNMENT);
		name.setFont(new Font("Stencil Std", Font.BOLD, 48));
		name.setBounds(90, 25, 255, 88);
		
		JLabel version = new JLabel("2.0");
		version.setFont(new Font("Stencil Std", Font.PLAIN, 20));
		version.setAlignmentX(Component.CENTER_ALIGNMENT);
		version.setBounds(178, 62, 255, 88);
		getContentPane().add(name);
		getContentPane().add(version);
		
		JLabel lblScore = new JLabel("Score");
		lblScore.setOpaque(true);
		lblScore.setBackground(Color.GRAY);
		lblScore.setHorizontalAlignment(SwingConstants.CENTER);
		lblScore.setFont(new Font("Stencil Std", Font.PLAIN, 15));
		lblScore.setAlignmentX(0.5f);
		lblScore.setBounds(350, 49, 100, 17);
		getContentPane().add(lblScore);
		
		scoreLab.setOpaque(true);
		scoreLab.setHorizontalAlignment(SwingConstants.CENTER);
		scoreLab.setFont(new Font("Stencil Std", Font.PLAIN, 12));
		scoreLab.setBackground(Color.GRAY);
		scoreLab.setAlignmentX(0.5f);
		scoreLab.setBounds(350, 62, 100, 51);
		getContentPane().add(scoreLab);
		
		JLabel lblHigh = new JLabel("High Score");
		lblHigh.setOpaque(true);
		lblHigh.setBackground(Color.GRAY);
		lblHigh.setHorizontalAlignment(SwingConstants.CENTER);
		lblHigh.setFont(new Font("Stencil Std", Font.PLAIN, 15));
		lblHigh.setAlignmentX(0.5f);
		lblHigh.setBounds(225, 49, 100, 17);
		getContentPane().add(lblHigh);
		
		highScore.setOpaque(true);
		highScore.setHorizontalAlignment(SwingConstants.CENTER);
		highScore.setFont(new Font("Stencil Std", Font.PLAIN, 12));
		highScore.setBackground(Color.GRAY);
		highScore.setAlignmentX(0.5f);
		highScore.setBounds(225, 62, 100, 51);
		getContentPane().add(highScore);
		
		//add listener for keys
		addKeyListener(new BKeyListener());
		
		//Set game to center of screen
		setLocationRelativeTo(null);
		setVisible(true);
	}
	public void lost()
	{
		lost = true;
	}
	
	public void addLabel(JLabel lab)
	{
		lab.setSize(1000,500);
		JLabel label_1 = new JLabel("");
		label_1.setBackground(Color.RED);
		label_1.setOpaque(true);
		label_1.setBounds(150, 150, 1000, 5000);
		getContentPane().add(lab);
		getContentPane().add(lab);
			
	
	}
	public void updateScore(int num1, int num2)
	{
		scoreLab.setText("" + num1);
		highScore.setText("" + num2);
	}
	//KeyListener
	class BKeyListener extends KeyAdapter
	{
		public void keyPressed(KeyEvent event)
		{
			if (lost == false)
			{
			switch (event.getKeyCode())
			{
			case 37:
				GameFunction.moveMethod("left");
				break;
			case 38:
				GameFunction.moveMethod("up");
				break;
			case 39:
				GameFunction.moveMethod("right");
				break;
			case 40:
				GameFunction.moveMethod("down");
				break;
			}
			}
			
		}
	}
}
